import hilog from '@ohos.hilog';

class Log {
  private getTemplate(list: any[]): string {
    const template = list.map(item => typeof item === 'number' ? '%{public}d' : '%{public}s')
    return template.join(' ')
  }

  info(tag: string, ...arg) {
    const template = this.getTemplate(arg)
    hilog.info(0x0000, tag, template, ...arg)
  }

  warn(tag: string, ...arg) {
    const template = this.getTemplate(arg)
    hilog.warn(0x0000, tag, template, ...arg)
  }

  debug(tag: string, ...arg) {
    const template = this.getTemplate(arg)
    hilog.debug(0x0000, tag, template, ...arg)
  }

  error(tag: string, ...arg) {
    const template = this.getTemplate(arg)
    hilog.error(0x0000, tag, template, ...arg)
  }
}

const log = new Log();

export default log